<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Test03</title>
    <style>
        th{
            background-color: #50afeb;
        }
        input{
            border-color: #50afeb;
            border-radius: 5px;
            height: 25px;
        }
        tr:hover{
            background-color: aqua;
        }
        input:focus{
            background-color: cadetblue;
        }
    </style>
</head>
<body>

<div>
    <table border="1px" widtd="600px" align="center" cellspacing="0px" cellpadding="5px" style="width: 700px" id="a">
        <tr>
            <th>学号</th>
            <th>姓名</th>
            <th>操作</th>
        </tr>

        <tr>
            <td>001</td>
            <td>zhangsan</td>
            <td>
                <a href='javascript:void(0)' onclick='deleteRow(this)'>删除</a>
            </td>
        </tr>

        <tr>
            <td>002</td>
            <td>lisi</td>
            <td>
                <a href='javascript:void(0)' onclick='deleteRow(this)'>删除</a>
            </td>
        </tr>
    </table>
    <br/>
</div>

<div align="center">
        学号:<input type="text" id="id" size="30">
        姓名:<input type="text" id="name" size="30">
        <input type="button" value="添加一行数据" onclick="add()" height="25px">
    </div>
<script>
    function add() {
        let valueId = document.getElementById("id").value;
        let valueName = document.getElementById("name").value;
        document.getElementById("id").value="";
        document.getElementById("name").value="";
        let tr = document.createElement("tr");
        let tdId = document.createElement("td");
        let tdName = document.createElement("td");
        let tdA = document.createElement("td");
        tdA.innerHTML="<a href=\"javascript:void(0)\" onclick=\"deleteRow(this)\">删除</a>"
        tdId.innerText=valueId;
        tdName.innerText=valueName;
        tr.appendChild(tdId);
        tr.appendChild(tdName);
        tr.appendChild(tdA)
        let table = document.getElementById("a");
        table.appendChild(tr);
    }

    function deleteRow(obj){
        if(confirm("真的要删除吗")){
            let tr = obj.parentNode.parentNode;
            tr.remove();
        }
    }
</script>
</body>
</html>